<script setup>
import ChildComponent1 from "./ChildComponent1.vue";
import ChildComponent2 from "./ChildComponent2.vue";
import { ref } from "vue";

const xd = ref(true);
</script>
<template>
  <h1>父组件</h1>
  <button @click="() => (xd = !xd)">切换组件</button>
  <KeepAlive>
    <ChildComponent1 v-if="xd" />
  </KeepAlive>
  <ChildComponent2 v-if="!xd" />
</template>
